import { nextTick } from "../utils";
let queue = []
let has = []
let pending = false
export function queenWatcher(watcher){
    const id = watcher.id
    if(has.indexOf(id) === -1){
        has.push(id)
        queue.push(watcher)
        if(!pending){
            // setTimeout(()=>{
            //     flushQueue()
            // },0)
            nextTick(flushQueue)
            pending = true
        }
    }
}

function flushQueue(){
    queue.forEach((w)=>{
        w.run()
    })
    queue = []
    has= []
    pending = false
}